package org.mch.func.file.content;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.Insets;

import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTabbedPane;
import javax.swing.JTextArea;
import javax.swing.border.LineBorder;

import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea;
import org.mch.biz.ui.FuncEvent;
import org.mch.biz.ui.FuncPanel;
import org.mch.func.swing.MNewUI;
import org.mch.swingm.ext.METextChooser;
import org.mch.swingm.obj.MItem;

/**
 * 描述：文件名操作功能；</BR>
 * 
 * @author MC、ZL；
 * 
 */
public class ClientPanel extends FuncPanel {
	private static final long serialVersionUID = 1L;
	private JButton btnExecute;
	private ButtonGroup buttonGroup;
	private JRadioButton rdbtn_oldnew;
	private JCheckBox check_floder;
	private JTabbedPane tabbedPane;
	private JPanel panel_6;
	private JPanel panel_7;
	private JScrollPane scrollPane;
	private JTextArea text_repgz;
	private METextChooser file_path;
	private JCheckBox check_searchchild;
	private JSplitPane splitPane;
	private JPanel panel_1;
	private JScrollPane scrollPane_1;
	private JScrollPane scrollPane_2;
	private RSyntaxTextArea textRegex;
	private RSyntaxTextArea textRepText;
	private JSplitPane splitPane_1;
	private JPanel panel;
	private JPanel panel_2;
	private JPanel panel_3;

	public ClientPanel() {
		initComponents();
	}

	private void initComponents() {
		setLayout(new BorderLayout(0, 0));
		add(getSplitPane(), BorderLayout.CENTER);
		getButtonGroup();
	}

	protected FuncEvent createEvent() {
		return new ClientEvent(this);
	}

	public JButton getBtnExecute() {
		if (btnExecute == null) {
			btnExecute = new JButton("\u6267\u884C");
			btnExecute.setFont(new Font("宋体", Font.PLAIN, 16));
			btnExecute.setMargin(new Insets(2, 2, 2, 2));
			btnExecute.addActionListener(getEvent());
		}
		return btnExecute;
	}

	public ButtonGroup getButtonGroup() {
		if (buttonGroup == null) {
			buttonGroup = new ButtonGroup();
			buttonGroup.add(getRdbtn_oldnew());
		}
		return buttonGroup;
	}

	public JRadioButton getRdbtn_oldnew() {
		if (rdbtn_oldnew == null) {
			rdbtn_oldnew = new JRadioButton("按文本框中键值对规则逐个替换：");
			rdbtn_oldnew.setBorder(new LineBorder(Color.LIGHT_GRAY));
			rdbtn_oldnew.setBounds(7, 9, 219, 23);
			rdbtn_oldnew.setFont(new Font("宋体", Font.PLAIN, 12));
		}
		return rdbtn_oldnew;
	}

	public JCheckBox getCheck_floder() {
		if (check_floder == null) {
			check_floder = new JCheckBox("是否修改文件夹名");
			check_floder.setToolTipText("");
			check_floder.setBounds(234, 9, 141, 23);
			check_floder.setFont(new Font("宋体", Font.BOLD, 12));
		}
		return check_floder;
	}

	public JTabbedPane getTabbedPane() {
		if (tabbedPane == null) {
			tabbedPane = new JTabbedPane(JTabbedPane.TOP);
			tabbedPane.setFont(new Font("宋体", Font.PLAIN, 14));
			tabbedPane.addTab("基本文件名操作", null, getPanel_6(), null);
			tabbedPane.addTab("文件名称替换", null, getPanel_7(), null);
		}
		return tabbedPane;
	}

	public JPanel getPanel_6() {
		if (panel_6 == null) {
			panel_6 = new JPanel();
			panel_6.setLayout(new BorderLayout(0, 0));
			panel_6.add(getSplitPane_1(), BorderLayout.CENTER);
			panel_6.add(getPanel_3(), BorderLayout.NORTH);
		}
		return panel_6;
	}

	public JPanel getPanel_7() {
		if (panel_7 == null) {
			panel_7 = new JPanel();
			panel_7.setLayout(null);
			panel_7.add(getRdbtn_oldnew());
			panel_7.add(getCheck_floder());
			panel_7.add(getScrollPane());
			panel_7.add(getCheck_searchchild());
		}
		return panel_7;
	}

	public JScrollPane getScrollPane() {
		if (scrollPane == null) {
			scrollPane = new JScrollPane();
			scrollPane.setBounds(7, 44, 656, 450);
			scrollPane.setViewportView(getText_repgz());
		}
		return scrollPane;
	}

	public JTextArea getText_repgz() {
		if (text_repgz == null) {
			text_repgz = new JTextArea();
		}
		return text_repgz;
	}

	public METextChooser getFile_path() {
		if (file_path == null) {
			file_path = new METextChooser(new MItem("目录："), METextChooser.SELECT_FOLDER);
			file_path.setPreferredSize(new Dimension(600, 33));
		}
		return file_path;
	}

	public JCheckBox getCheck_searchchild() {
		if (check_searchchild == null) {
			check_searchchild = new JCheckBox("是否搜索子文件夹");
			check_searchchild.setToolTipText("");
			check_searchchild.setFont(new Font("宋体", Font.BOLD, 12));
			check_searchchild.setBounds(388, 8, 141, 23);
		}
		return check_searchchild;
	}

	public JSplitPane getSplitPane() {
		if (splitPane == null) {
			splitPane = new JSplitPane();
			splitPane.setDividerSize(5);
			splitPane.setOrientation(JSplitPane.VERTICAL_SPLIT);
			splitPane.setRightComponent(getTabbedPane());
			splitPane.setLeftComponent(getPanel_1());
			splitPane.setDividerLocation(60);
		}
		return splitPane;
	}

	public JPanel getPanel_1() {
		if (panel_1 == null) {
			panel_1 = new JPanel();
			panel_1.setLayout(null);
		}
		return panel_1;
	}

	public JScrollPane getScrollPane_1() {
		if (scrollPane_1 == null) {
			scrollPane_1 = new JScrollPane();
			scrollPane_1.setBorder(MNewUI.createTitledBorder("\u88AB\u66FF\u6362\u7684\u6B63\u5219\u8868\u8FBE\u5F0F"));
			scrollPane_1.setViewportView(getTextRegex());
		}
		return scrollPane_1;
	}

	public JScrollPane getScrollPane_2() {
		if (scrollPane_2 == null) {
			scrollPane_2 = new JScrollPane();
			scrollPane_2.setBorder(MNewUI.createTitledBorder("\u66FF\u6362\u540E\u7684\u5185\u5BB9"));
			scrollPane_2.setViewportView(getTextRepText());
		}
		return scrollPane_2;
	}

	public RSyntaxTextArea getTextRegex() {
		if (textRegex == null) {
			textRegex = new RSyntaxTextArea();
			textRegex.setFont(new Font("宋体", Font.PLAIN, 14));
			textRegex.setBorder(new LineBorder(new Color(0, 0, 0)));
		}
		return textRegex;
	}

	public RSyntaxTextArea getTextRepText() {
		if (textRepText == null) {
			textRepText = new RSyntaxTextArea();
			textRepText.setFont(new Font("宋体", Font.PLAIN, 14));
			textRepText.setBorder(new LineBorder(new Color(0, 0, 0)));
		}
		return textRepText;
	}

	public JSplitPane getSplitPane_1() {
		if (splitPane_1 == null) {
			splitPane_1 = new JSplitPane();
			splitPane_1.setDividerLocation(500);
			splitPane_1.setDividerSize(2);
			splitPane_1.setLeftComponent(getPanel());
			splitPane_1.setRightComponent(getPanel_2());
		}
		return splitPane_1;
	}

	public JPanel getPanel() {
		if (panel == null) {
			panel = new JPanel();
			panel.setLayout(new BorderLayout(0, 0));
			panel.add(getScrollPane_1(), BorderLayout.CENTER);
		}
		return panel;
	}

	public JPanel getPanel_2() {
		if (panel_2 == null) {
			panel_2 = new JPanel();
			panel_2.setLayout(new BorderLayout(0, 0));
			panel_2.add(getScrollPane_2(), BorderLayout.CENTER);
		}
		return panel_2;
	}

	public JPanel getPanel_3() {
		if (panel_3 == null) {
			panel_3 = new JPanel();
			panel_3.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 5));
			panel_3.add(getFile_path());
			panel_3.add(getBtnExecute());
		}
		return panel_3;
	}
}